﻿using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Remote;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using AutoTestingFramework.Core.Configurations;

namespace AutoTestingFramework.Core.WebDrivers
{
    public class IEWebDriverWrapper : InternetExplorerDriver
    {
        public IEWebDriverWrapper(string ieDriverDirectoryPath, TimeSpan commandTimeout)
            : base(ieDriverDirectoryPath, new InternetExplorerOptions()
            {
                IgnoreZoomLevel = true,
                IntroduceInstabilityByIgnoringProtectedModeSettings = true,
                EnableNativeEvents = true

            }, commandTimeout)
        {

        }
    }

    public class ChromeWebDriverWrapper : ChromeDriver
    {
        public ChromeWebDriverWrapper(string chromeDriverDirectoryPath, TimeSpan commandTimeout)
            : base(GetDefaultChromeService(chromeDriverDirectoryPath),
                   GetDefaultChromeOption(),
                   commandTimeout)
        {

        }

        private static ChromeDriverService GetDefaultChromeService(string chromeDriverDirectoryPath)
        {
            var chromeDriverService = ChromeDriverService.CreateDefaultService(chromeDriverDirectoryPath);
            chromeDriverService.SuppressInitialDiagnosticInformation = true;

            return chromeDriverService;
        }

        private static ChromeOptions GetDefaultChromeOption()
        {
            var option = new ChromeOptions();
            option.AddArgument("--log-level=3");

            return option;
        }
    }

    public class FirefoxWebDriverWrapper : FirefoxDriver
    {
        public FirefoxWebDriverWrapper(TimeSpan commandTimeout, string firefoxDriverDirectoryPath = null)
            : base(GetDefaultFirefoxBinary(),
                   GetDefaultFirefoxProfile(),
                   commandTimeout) 
        {

        }

        private static FirefoxBinary GetDefaultFirefoxBinary()
        {
            var binary = new FirefoxBinary();
            return binary;
        }

        private static FirefoxProfile GetDefaultFirefoxProfile()
        {
            var profile = new FirefoxProfile();
            profile.EnableNativeEvents = false;
            profile.AcceptUntrustedCertificates = true;
            profile.AlwaysLoadNoFocusLibrary = true;

            return profile;
        }

    }
    public class RemoteWebDriverWrapper : RemoteWebDriver
    {
        public RemoteWebDriverWrapper(Uri remoteHubURL, Capability capability)
            : base(remoteHubURL, capability.GetDesiredCapabilities())
        {

        }

    }
}
